﻿cmake_minimum_required(VERSION 3.15)
project(ModbusSlaveSimulator)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 查找Boost库
if(WIN32)
    set(Boost_USE_STATIC_LIBS ON)
endif()
find_package(Boost 1.75 REQUIRED COMPONENTS system program_options)

# 源文件
set(SOURCES
    src/main.cpp
    src/modbus_slave.hpp
    src/modbus_server.hpp
    src/data_persistence.hpp
)

# 可执行文件
add_executable(modbus_slave_simulator ${SOURCES})


# 包含目录
include_directories(modbus_slave_simulator
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${Boost_INCLUDE_DIRS}
)

# 链接库目录
target_link_directories(modbus_slave_simulator
    PRIVATE
        ${Boost_LIBRARY_DIRS}
)

# 链接库
target_link_libraries(modbus_slave_simulator
    PRIVATE
        Boost::system
        Boost::program_options
)

# Windows 兼容
if(WIN32)
    target_compile_definitions(modbus_slave_simulator PRIVATE _WIN32_WINNT=0x0601)
endif()

# 编译器特定的选项
if(MSVC)
    # MSVC编译器选项
    target_compile_options(modbus_slave_simulator PRIVATE /W4)
else()
    # GCC/Clang编译器选项
    target_compile_options(modbus_slave_simulator PRIVATE -Wall -Wextra -Wpedantic)
endif()

# 安装目标
install(TARGETS modbus_slave_simulator DESTINATION bin)
